function back(){
  $("#back").on("touchstart",function(){
  	closeWin();
  })
}
//添加样式和移除样式
function addActive(ele1,ele2){
	ele1.addClass("active");
	ele2.removeClass("active");
}
//打开一个新窗口，不带参数
function openPage(name,url){
	api.openWin({
	    name: name,
	    url: url,
      scrollEnabled:false
	});
}
//打开一个新窗口，可以弹动
function openPageAble(name,url){
	api.openWin({
	    name: name,
	    url: url
	});
}
//关闭窗口
function closeWin(){
	api.closeWin();
}
//会消失的toast,msg为提示内容，local为位置，有top,bottom,middle
function toast(msg,local){
	api.toast({
	    msg: msg,
	    duration: 2000,
	    location: local
	});
}
//菊花进度
function showProgress(){
  api.showProgress({
    title: '努力加载中...',
    text: '先喝杯茶...',
    modal: false
  });
}
function hideProgress(){
  api.hideProgress();
}
function getLocalTime(nS) { 
	//将时间戳（十三位时间搓，也就是带毫秒的时间搓）转换成时间格式
	// d.cTime = 1539083829787
	let date = new Date(nS);
	let year = date.getFullYear();
	let month = date.getMonth()+1;
	let day = date.getDate();
	month = month < 10 ? "0"+month:month;
	day = day < 10 ? "0"+day:day;
	date = year+'-'+month+'-'+day;
	return date;
}
//时间戳转时间
function timestampToTime(timestamp) {
      var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
      Y = date.getFullYear() + '-';
      M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
      D = date.getDate() + ' ';
      h = date.getHours() + ':';
      m = date.getMinutes() + ':';
      s = date.getSeconds();
      return Y+M+D+h+m+s;
  }
//时间转换
/**
 * 将日期格式化成指定格式的字符串
 * 用法：formatDate(new Date(), 'yyyy-MM-ddTHH:mm:ssZ'); //2017-04-07T04:27:47Z  formatDate(new Date(), 'yyyy-MM-dd'); // 2016-09-02
 */
function formatDate(date, fmt)
{
    date = date == undefined ? new Date() : date;
    date = typeof date == 'number' ? new Date(date) : date;
    fmt = fmt || 'yyyy-MM-dd HH:mm:ss';
    var obj =
    {
        'y': date.getFullYear(), // 年份，注意必须用getFullYear
        'M': date.getMonth() + 1, // 月份，注意是从0-11
        'd': date.getDate(), // 日期
        'q': Math.floor((date.getMonth() + 3) / 3), // 季度
        'w': date.getDay(), // 星期，注意是0-6
        'H': date.getHours(), // 24小时制
        'h': date.getHours() % 12 == 0 ? 12 : date.getHours() % 12, // 12小时制
        'm': date.getMinutes(), // 分钟
        's': date.getSeconds(), // 秒
        'S': date.getMilliseconds() // 毫秒
    };
    var week = ['天', '一', '二', '三', '四', '五', '六'];
    for(var i in obj)
    {
        fmt = fmt.replace(new RegExp(i+'+', 'g'), function(m)
        {
            var val = obj[i] + '';
            if(i == 'w') return (m.length > 2 ? '星期' : '周') + week[val];
            for(var j = 0, len = val.length; j < m.length - len; j++) val = '0' + val;
            return m.length == 1 ? val : val.substring(val.length - m.length);
        });
    }
    return fmt;
}
//获取登录aid和deviceId
function islogin(){
  // var aid=$api.getStorage('aid');
  // var jwt=$api.getStorage('jwt');
  // // console.log(aid);
  // // console.log(deviceId);
  // api.ajax({
  //   url: 'http://47.104.170.122/v1/portal/apigateway/universityfacade/api/paAdmin/isLogin?token='+jwt+'&aid='+aid,
  //   method: 'GET',
  //   headers: {
  //     "Access-Control-Allow-Origin": "*",
  //     "Access-Control-Allow-Headers": "Authorization"
  //   }
  // }, function(ret, err) {
    // console.log(JSON.stringify(err.body));
    //if(err.body == 'true'){
      // alert('账号在别处登录，请检查账号是否被盗用');
      // $api.clearStorage();
      // api.rebootApp();
      // return false;
    //}
    // if(err.statusCode == 401){
    //   alert("该账号在另一台设备登录，如不是本人操作，请尽快修改密码");
    //   $api.clearStorage();
    //   api.rebootApp();
    // }
      // if (ret) {
      //   functionRet(ret);
      // } else {
      //   functionErr(err);
      // }
  //});
}

//获取数据
function get(url,functionRet,functionErr){
  var jwt=$api.getStorage('jwt');
  api.ajax({
    url: 'http://47.104.170.122/v1/portal/apigateway/universityfacade'+url+'?token='+jwt,
    method: 'GET',
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "Authorization",
      "Content-Type" : 'application/json; charset=utf-8'
    }
  }, function(ret, err) {
      if (ret) {
        functionRet(ret);
      } else {
        functionErr(err);
      }
  });
}
function getU(url,functionRet,functionErr){
  var jwt=$api.getStorage('jwt');
  api.ajax({
    url: 'http://47.104.170.122/v1/portal/apigateway/universityfacade'+url+'&token='+jwt,
    method: 'GET',
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "Authorization",
      "Content-Type" : 'application/json; charset=utf-8'
    }
  }, function(ret, err) {
      if (ret) {
        functionRet(ret);
      } else {
        functionErr(err);
      }
  });
}
//获取数据
function getNew(url,functionRet,functionErr){
  var jwt=$api.getStorage('jwt');
  api.ajax({
    url: 'http://47.104.170.122/v1/portal/schoolEnterprise'+url+'?token='+jwt,
    method: 'GET',
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "Authorization",
      "Content-Type" : 'application/json; charset=utf-8'
    }
  }, function(ret, err) {
    // if(err.statusCode == 401){
    //   alert("该账号在另一台设备登录，如不是本人操作，请尽快修改密码");
    //   $api.clearStorage();
    //   api.rebootApp();
    // }
      if (ret) {
        functionRet(ret);
      } else {
        functionErr(err);
      }
  });
}
function getNewU(url,functionRet,functionErr){
  var jwt=$api.getStorage('jwt');
  api.ajax({
    url: 'http://47.104.170.122/v1/portal/schoolEnterprise'+url+'&token='+jwt,
    method: 'GET',
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "Authorization",
      "Content-Type" : 'application/json; charset=utf-8'
    }
  }, function(ret, err) {
    // if(err.statusCode == 401){
    //   alert("该账号在另一台设备登录，如不是本人操作，请尽快修改密码");
    //   $api.clearStorage();
    //   api.rebootApp();
    // }
      if (ret) {
        functionRet(ret);
      } else {
        functionErr(err);
      }
  });
}
//提交数据post
function post(url,data,functionRet,functionErr){
  var jwt=$api.getStorage('jwt');
  api.ajax({
    url: 'http://47.104.170.122/v1/portal/apigateway/universityfacade'+url+'?token='+jwt,
    method: 'POST',
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "Authorization",
      "Content-Type" : 'application/json; charset=utf-8'
    },
    data:{body:data}
  }, function(ret, err) {
      if (ret) {
        functionRet(ret);
      } else {
        functionErr(err);
      }
  });
}
function postU(url,data,functionRet,functionErr){
  var jwt=$api.getStorage('jwt');
  api.ajax({
    url: 'http://47.104.170.122/v1/portal/apigateway/universityfacade'+url+'&token='+jwt,
    method: 'POST',
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "Authorization",
      "Content-Type" : 'application/json; charset=utf-8'
    },
    data:{body:data}
  }, function(ret, err) {
      if (ret) {
        functionRet(ret);
      } else {
        functionErr(err);
      }
  });
}
//提交数据post
function postNew(url,data,functionRet,functionErr){
  var jwt=$api.getStorage('jwt');
  api.ajax({
    url: 'http://47.104.170.122/v1/portal/schoolEnterprise'+url+'?token='+jwt,
    method: 'POST',
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "Authorization",
      "Content-Type" : 'application/json; charset=utf-8'
    },
    data:{body:data}
  }, function(ret, err) {
      if (ret) {
        functionRet(ret);
      } else {
        functionErr(err);
      }
  });
}
function postNewU(url,data,functionRet,functionErr){
  var jwt=$api.getStorage('jwt');
  api.ajax({
    url: 'http://47.104.170.122/v1/portal/schoolEnterprise'+url+'&token='+jwt,
    method: 'POST',
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "Authorization",
      "Content-Type" : 'application/json; charset=utf-8'
    },
    data:{body:data}
  }, function(ret, err) {
      if (ret) {
        functionRet(ret);
      } else {
        functionErr(err);
      }
  });
}
function show_post(url,data,functionRet,functionErr){
  api.showProgress({
    title: '发布中...',
    text: '发布中，请稍后...',
    modal: false
  });
  var jwt=$api.getStorage('jwt');
  islogin();
  api.ajax({
    url: 'http://47.104.170.122/v1/portal/apigateway/universityfacade'+url+'?token='+jwt,
    method: 'POST',
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "Authorization",
      "Content-Type" : 'application/json; charset=utf-8'
    },
    data:{body:data}
  }, function(ret, err) {
      if (ret) {
        functionRet(ret);
      } else {
        functionErr(err);
      }
  });
}
//提交数据put
function put(url,data,functionRet,functionErr){
  var jwt=$api.getStorage('jwt');
  islogin();
  api.ajax({
    url: 'http://47.104.170.122/v1/portal/apigateway/universityfacade'+url+'?token='+jwt,
    method: 'PUT',
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "Authorization",
      "Content-Type" : 'application/json; charset=utf-8'
    },
    data:{body:data}
  }, function(ret, err) {
      if (ret) {
        functionRet(ret);
      } else {
        functionErr(err);
      }
  });
}
//删除数据delete
function deleteData(url,data,functionRet,functionErr){
  var jwt=$api.getStorage('jwt');
  islogin();
  api.ajax({
    url: 'http://47.104.170.122/v1/portal/apigateway/universityfacade'+url+'?token='+jwt,
    method: 'DELETE',
    dataType:'json',
    //tag: 'publish',
    //type: 'DELETE',
    data:{body:data},
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "Authorization",
      "Content-Type" : 'application/json; charset=utf-8'
    }
  }, function(ret, err) {
      if (ret) {
        functionRet(ret);
      } else {
        functionErr(err);
      }
  });
}
//删除数据delete
function deleteDataU(url,data,functionRet,functionErr){
  var jwt=$api.getStorage('jwt');
  islogin();
  api.ajax({
    url: 'http://47.104.170.122/v1/portal/apigateway/universityfacade'+url+'&token='+jwt,
    method: 'DELETE',
    dataType:'json',
    //tag: 'publish',
    //type: 'DELETE',
    data:{body:data},
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "Authorization",
      "Content-Type" : 'application/json; charset=utf-8'
    }
  }, function(ret, err) {
      if (ret) {
        functionRet(ret);
      } else {
        functionErr(err);
      }
  });
}
